// 加载角色列表
let ROLE_LIST = (state, payload) => {
    state.roles = [...payload];
}

// 根据角色id，加载路由权限
let LOAD_ROUTE_PERMISSION = (state, payload) => {
    state.routes = [...payload];
}

// 添加角色
let ADD_ROLE = (state, role) => {
    state.roles.push(role);
}

// 编辑角色
let EDIT_ROLE = (state, payload) => {
    let index = state.roles.findIndex(roles => roles.role_id === payload.role_id);
    if (index !== -1) {
        // 使用 splice 方法更新数组，以便触发响应式更新机制
        state.roles.splice(index, 1, payload);
    }
}

// 删除角色
let REMOVE_ROLE = (state, index) => {
    state.roles.splice(index, 1);
}

// 加载操作按钮权限
let LOAD_OPERATION_PERMISSION = (state, payload) => {
    state.operations = [...payload];
}


export default {
    ROLE_LIST,
    LOAD_ROUTE_PERMISSION,
    ADD_ROLE,
    EDIT_ROLE,
    REMOVE_ROLE,
    LOAD_OPERATION_PERMISSION,
}
